package com.sinozo.data.utils;

import org.apache.flink.api.java.utils.ParameterTool;

import java.util.HashMap;
import java.util.Map;

public class ConfigUtil {

   /**
    * @param args
    * @return org.apache.flink.api.java.utils.ParameterTool
    * @date 2023/5/11 15:48:53
    * @author zhaoyb
    * @description
    */
    public static ParameterTool createParameterTool(final String[] args) throws Exception {
        String configPath = ConfigUtil.class.getClassLoader().getResource("config.properties").getPath();
        return ParameterTool
                .fromPropertiesFile(configPath)
                .mergeWith(ParameterTool.fromArgs(args))
                .mergeWith(ParameterTool.fromSystemProperties())
                .mergeWith(ParameterTool.fromMap(getenv()));
    }


    //获取 Job 设置的环境变量
    private static Map<String, String> getenv() {
        Map<String, String> map = new HashMap<>();
        for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
            map.put(entry.getKey().toLowerCase().replace('_', '.'), entry.getValue());
        }
        return map;
    }


}
